package br.com.webhomesites.configuracao.view;

import br.com.webhomesites.configuracao.contracts.IUsuarioView;
import br.com.webhomesites.configuracao.utils.ConfiguracaoInstancias;
import java.awt.AWTKeyStroke;
import java.awt.Component;
import java.awt.KeyboardFocusManager;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.*;

public class UsuarioView extends javax.swing.JInternalFrame implements IUsuarioView {
     
    //construtor da classe. carrega os componentes
    public UsuarioView() {
        initComponents();        
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        painelCentralUser = new javax.swing.JPanel();
        labelUsuarioNome = new javax.swing.JLabel();
        txtUsuarioNome = new javax.swing.JTextField();
        labelUsuarioCodigo = new javax.swing.JLabel();
        labelBairroUser = new javax.swing.JLabel();
        txtUsuarioLogin = new javax.swing.JTextField();
        txtUsuarioCodigo = new javax.swing.JTextField();
        labelUsuarioSenha = new javax.swing.JLabel();
        txtUsuarioSenha = new javax.swing.JPasswordField();
        btnNovo = new javax.swing.JButton();
        btnRemover = new javax.swing.JButton();
        btnSalvar = new javax.swing.JButton();
        btnCancelar = new javax.swing.JButton();
        btnPesquisar = new javax.swing.JButton();

        setClosable(true);
        setIconifiable(true);

        painelCentralUser.setBorder(javax.swing.BorderFactory.createTitledBorder("Cadastro de Usuários"));

        labelUsuarioNome.setText("Nome");

        labelUsuarioCodigo.setText("Cód.Usuário");

        labelBairroUser.setText("Login");

        txtUsuarioCodigo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtUsuarioCodigoActionPerformed(evt);
            }
        });

        labelUsuarioSenha.setText("Senha");

        txtUsuarioSenha.setText("jPasswordField1");

        javax.swing.GroupLayout painelCentralUserLayout = new javax.swing.GroupLayout(painelCentralUser);
        painelCentralUser.setLayout(painelCentralUserLayout);
        painelCentralUserLayout.setHorizontalGroup(
            painelCentralUserLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(painelCentralUserLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(painelCentralUserLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(painelCentralUserLayout.createSequentialGroup()
                        .addComponent(labelBairroUser)
                        .addGap(128, 128, 128)
                        .addComponent(labelUsuarioSenha))
                    .addGroup(painelCentralUserLayout.createSequentialGroup()
                        .addGroup(painelCentralUserLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(labelUsuarioCodigo, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(txtUsuarioCodigo))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(painelCentralUserLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(labelUsuarioNome)
                            .addComponent(txtUsuarioNome)))
                    .addGroup(painelCentralUserLayout.createSequentialGroup()
                        .addComponent(txtUsuarioLogin, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(txtUsuarioSenha, javax.swing.GroupLayout.PREFERRED_SIZE, 122, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        painelCentralUserLayout.setVerticalGroup(
            painelCentralUserLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(painelCentralUserLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(painelCentralUserLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelUsuarioNome)
                    .addComponent(labelUsuarioCodigo))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(painelCentralUserLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtUsuarioNome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtUsuarioCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(painelCentralUserLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelBairroUser)
                    .addComponent(labelUsuarioSenha))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(painelCentralUserLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtUsuarioLogin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtUsuarioSenha, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        btnNovo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/document-icon.png"))); // NOI18N
        btnNovo.setMnemonic('n');
        btnNovo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnNovoActionPerformed(evt);
            }
        });

        btnRemover.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/delete-icon.png"))); // NOI18N
        btnRemover.setMnemonic('x');
        btnRemover.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnRemoverActionPerformed(evt);
            }
        });

        btnSalvar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/save-icon.png"))); // NOI18N
        btnSalvar.setMnemonic('s');
        btnSalvar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSalvarActionPerformed(evt);
            }
        });

        btnCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/block-icon.png"))); // NOI18N
        btnCancelar.setMnemonic('c');
        btnCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelarActionPerformed(evt);
            }
        });

        btnPesquisar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/search-icon.png"))); // NOI18N
        btnPesquisar.setMnemonic('p');
        btnPesquisar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnPesquisarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(btnNovo, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(btnSalvar, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(btnRemover, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(btnCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, 52, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnPesquisar, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(painelCentralUser, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(painelCentralUser, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(btnSalvar, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btnRemover, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btnCancelar, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btnPesquisar, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btnNovo, javax.swing.GroupLayout.DEFAULT_SIZE, 47, Short.MAX_VALUE))
                .addContainerGap(19, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
    //ação do botão salvar
    private void btnSalvarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSalvarActionPerformed
 
    }//GEN-LAST:event_btnSalvarActionPerformed
    //ação do botão novo
    private void btnNovoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnNovoActionPerformed
       
    }//GEN-LAST:event_btnNovoActionPerformed
    //ação do botão pesquisar
    private void btnPesquisarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPesquisarActionPerformed
     
        
    }//GEN-LAST:event_btnPesquisarActionPerformed
    //ação do botão cancelar
    private void btnCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelarActionPerformed
      
    }//GEN-LAST:event_btnCancelarActionPerformed

    private void btnRemoverActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRemoverActionPerformed
       
    }//GEN-LAST:event_btnRemoverActionPerformed
    //ação do campo do código do usuário
    private void txtUsuarioCodigoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtUsuarioCodigoActionPerformed
       
    }//GEN-LAST:event_txtUsuarioCodigoActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnCancelar;
    private javax.swing.JButton btnNovo;
    private javax.swing.JButton btnPesquisar;
    private javax.swing.JButton btnRemover;
    private javax.swing.JButton btnSalvar;
    private javax.swing.JLabel labelBairroUser;
    private javax.swing.JLabel labelUsuarioCodigo;
    private javax.swing.JLabel labelUsuarioNome;
    private javax.swing.JLabel labelUsuarioSenha;
    private javax.swing.JPanel painelCentralUser;
    private javax.swing.JTextField txtUsuarioCodigo;
    private javax.swing.JTextField txtUsuarioLogin;
    private javax.swing.JTextField txtUsuarioNome;
    private javax.swing.JPasswordField txtUsuarioSenha;
    // End of variables declaration//GEN-END:variables

    @Override
    public void setCodigo(int codigo) {
        this.txtUsuarioCodigo.setText((Integer.toString(codigo)));
    }

    @Override
    public int getCodigo() {
        return Integer.parseInt(txtUsuarioCodigo.getText());
    }

    @Override
    public void setNome(String nome) {
        this.txtUsuarioNome.setText(nome);
    }

    @Override
    public String getNome() {
        return txtUsuarioNome.getText();
    }

    @Override
    public void setLogin(String login) {
        this.txtUsuarioLogin.setText(login);
    }

    @Override
    public String getLogin() {
        return txtUsuarioLogin.getText();
    }

    @Override
    public void setSenha(String senha) {
        this.txtUsuarioSenha.setText(senha);
    }

    @Override
    public String getSenha() {
        return txtUsuarioSenha.getPassword().toString();
    }

    @Override
    public void packAndShow() {
        //this.pack();  
        ConfiguracaoInstancias.getDesktop().getDesktop().add(this);
        this.setVisible(true);
    }

    @Override
    public void clearFields() {
        Component[] componentes = this.getContentPane().getComponents();  
          
        for (int i = 0; i < componentes.length; i++) {  
            if (componentes[i] instanceof JTextField) {  
                JTextField field = (JTextField)componentes[i];  
                field.setText("");  
            }  
        }  
    }

    @Override
    public void enableTxtUsuarioCodigo(boolean arg) {
        this.txtUsuarioCodigo.setEnabled(arg);
    }

    @Override
    public void enableTxtUsuarioNome(boolean arg) {
        this.txtUsuarioNome.setEnabled(arg);
    }

    @Override
    public void enableTxtUsuarioLogin(boolean arg) {
        this.txtUsuarioLogin.setEnabled(arg);
    }

    @Override
    public void enableTxtUsuarioSenha(boolean arg) {
        this.txtUsuarioSenha.setEnabled(arg);
    }

    @Override
    public void enableBtnAlterar(boolean arg) {
        this.btnPesquisar.setEnabled(arg);
    }

    @Override
    public void enableBtnRemover(boolean arg) {
        this.btnRemover.setEnabled(arg);
    }

    @Override
    public void enableBtnCancelar(boolean arg) {
        this.btnCancelar.setEnabled(arg);
    }

    @Override
    public void enableBtnSalvar(boolean arg) {
        this.btnSalvar.setEnabled(arg);
    }

    @Override
    public void enableBtnInserir(boolean arg) {
        this.btnNovo.setEnabled(arg);
    }

    @Override
    public void setInserirActionListener(ActionListener listener) {
        this.btnNovo.addActionListener(listener); 
    }

    @Override
    public void setRemoverActionListener(ActionListener listener) {
        this.btnRemover.addActionListener(listener); 
    }

    @Override
    public void setAlterarActionListener(ActionListener listener) {
        this.btnPesquisar.addActionListener(listener);
    }

    @Override
    public void setCancelarActionListener(ActionListener listener) {
        this.btnCancelar.addActionListener(listener); 
    }

    @Override
    public void setSalvarActionListener(ActionListener listener) {
        this.btnSalvar.addActionListener(listener); 
    }

    @Override
    public void setBtnSairActionListener(ActionListener listener) {
        //this.btnSair.addActionListener(listener); 
    }

}
